const https = require("https");
const fs = require("fs");

//创建请求  参数1：请求参数obj    参数2：请求得到响应的回调
const option = {
    hostname:"m.maizuo.com",
    port:443,//https端口号为443
    path:"/v4/api/film/now-playing?__t=1532313472004&page=1&count=5",
    method:"GET"
}

const request = https.request(option,(response)=>{
    console.log("得到了响应")
    //console.log(response)

    //监听response的data事件 取得里面的数据
    let result = "";
    response.on("data",(data)=>{
        console.log("接受到了数据")
        result+=data;
        console.log(result)
    })
    response.on("end",()=>{
        console.log("接受完毕")
        //创建写入文件
        fs.writeFileSync("./test.json",result)
    })
});

//监听错误
request.on("error",(error)=>{
    console.log(error)
});
//发送请求
request.end();